// channels 的仓库数据
import { getNewsChannels } from '@/services/newsService'

export default {
  namespaced: true, // 开启命名空间
  state: {
    channels: [],
    isLoading: false
  },
  mutations: {
    // 这里配置多种变异方式
    // state: 原来的状态
    // payload: 负荷
    setIsLoading (state, payload) {
      state.isLoading = payload
    },
    setData (state, payload) {
      state.channels = payload
    }
  },
  actions: {
    async fetchDatas (context, payload) {
      // 设置isLoading为true
      context.commit('setIsLoading', true)
      var channels = await getNewsChannels()
      // 设置channels为异步获取到的channels数据
      context.commit('setData', channels)
      // 设置isLoading为false
      context.commit('setIsLoading', false)
    }
  }
}
